package com.example.learnandroidprofiler;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button cpuProfilerBtn, memProfilerBtn, networkProfilerBtn, energyProfilerBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findView();
        initView();
        initData();
    }

    private void findView() {
        cpuProfilerBtn = findViewById(R.id.activity_main_cpu_profiler_btn);
        memProfilerBtn = findViewById(R.id.activity_main_mem_profiler_btn);
        networkProfilerBtn = findViewById(R.id.activity_main_network_profiler_btn);
        energyProfilerBtn = findViewById(R.id.activity_main_energy_profiler_btn);
    }

    // 设置监听器及初始化控件
    private void initView() {
        cpuProfilerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                demoForCpu();
            }
        });
        memProfilerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                demoForMemory();
            }
        });
        networkProfilerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                demoForNetwork();
            }
        });
        energyProfilerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                demoForEnergy();
            }
        });
    }

    // 初始化数据
    private void initData() {

    }

    // 跳转到处理器演示界面
    private void demoForCpu() {
        startActivity(new Intent(MainActivity.this, CpuProfilerActivity.class));
    }

    // 跳转到内存演示界面
    private void demoForMemory() {
        startActivity(new Intent(MainActivity.this, MemoryProfilerActivity.class));
    }

    // 跳转到网络演示界面
    private void demoForNetwork() {
        startActivity(new Intent(MainActivity.this, NetworkProfilerActivity.class));
    }

    // 跳转到耗电演示界面
    private void demoForEnergy() {
        startActivity(new Intent(MainActivity.this, EnergyProfilerActivity.class));
    }
}
